﻿using System;
using System.Collections.Generic;
using Web7.Ioc;

namespace Web7.Domain
{
    public class DomainService<T, TId> : IDomainService<T, TId>,IDependency where T : Entity<TId>
    {
        protected IRepository<T, TId> InnerRepository;

        public DomainService(IRepository<T,TId> repository)
        {
            InnerRepository = repository;
        }

        public void Create(T entity)
        {
            InnerRepository.Create(entity);
        }

        public void Update(T entity)
        {
            InnerRepository.Update(entity);
        }

        public void Delete(T entity)
        {
            InnerRepository.Delete(entity);
        }

        public void Delete(IEnumerable<T> entities)
        {
            InnerRepository.Delete(entities);
        }

        public void Delete(params TId[] ids)
        {
            InnerRepository.Delete(ids);
        }

        public void Delete(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
        {
            InnerRepository.Delete(predicate);
        }

        public T Get(TId id)
        {
            return InnerRepository.Get(id);
        }

        public T Get(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
        {
            return InnerRepository.Get(predicate);
        }

        public int Count(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
        {
            return InnerRepository.Count(predicate);
        }

        public IEnumerable<T> Fetch(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
        {
            return InnerRepository.Fetch(predicate);
        }

        public IEnumerable<T> Fetch(System.Linq.Expressions.Expression<Func<T, bool>> predicate, Action<Orderable<T>> order)
        {
            return InnerRepository.Fetch(predicate, order);
        }

        public IEnumerable<T> Fetch(System.Linq.Expressions.Expression<Func<T, bool>> predicate, Action<Orderable<T>> order, int skip, int count)
        {
            return InnerRepository.Fetch(predicate, order, skip, count);
        }
    }

    public class DomainService<T> : DomainService<T, Guid>, IDomainService<T> where T : Entity
    {
        public DomainService(IRepository<T> repository)
            : base(repository)
        {
        }
    }
}
